﻿
using System ;
using System.Drawing ;
using System.Windows.Forms ;
using System.Configuration ;


namespace MskEdit.Frontend
{
    public partial class ProgramSettingsForm : Form
    {
        public ProgramSettingsForm()
        {
            InitializeComponent() ;
        }
        
        public void editProgramSettings( ApplicationSettingsBase ProgramSettings )
        {
            ProgramSettingsPropertyGrid.SelectedObject = ProgramSettings ;
            this.Show() ;
        }
        
        void handleButtonClick( object sender, EventArgs e )
        {            
            ApplicationSettingsBase ProgramSettings = 
                ProgramSettingsPropertyGrid.SelectedObject as ApplicationSettingsBase ;
            
            if ( ProgramSettings != null )
            {
                if ( sender == defaultsButton )
                    ProgramSettings.Reset() ;
                
                if ( ( sender == reloadButton ) || ( sender == cancelButton ) )
                    ProgramSettings.Reload() ;
                
                if ( ( sender == defaultsButton ) || ( sender == reloadButton ) || ( sender == cancelButton ) )
                    ProgramSettingsPropertyGrid.SelectedObject = ProgramSettings ; // Resync
                
                if ( sender == okButton )
                    ProgramSettings.Save() ;
            }
            
            if ( ( sender == okButton ) || ( sender == cancelButton ) )
                this.Hide() ;            
        }
    }
}
